<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> 
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<div class="container-fluid">
	<div class="tabbable" id="tabs-598782">
 		<ul class="nav nav-tabs">			
            <li id="user_list" class="active"><a href="#userList" data-toggle="tab">用户列表</a></li>
           <shiro:hasPermission name="user:create"> 
            <li id="add_user"><a href="#adduser-pane" data-toggle="tab" id="add_user">添加用户</a></li>
           </shiro:hasPermission>
          
            <li style="float:right;">
            	<div>
					<input type="text" name="name-text" placeholder="根据用户名查找用户" style="margin:0;">
					<button type="submit" class="search-btn" id="name-search" name="name">
					 <i	class="glyphicon glyphicon-search"></i>
					</button>

					<input type="text" name="phone-text" placeholder="根据手机号查找用户" style="margin:0;">
					<button type="submit" class="search-btn" id="phone-search" name="phone">
					 <i	class="glyphicon glyphicon-search"></i>
					</button>
				</div>
            </li>
		</ul> 
		
		<!-- 用户列表容器 -->
		<div class="tab-content">
		<div class="tab-pane in active" id="userList" > </div>
		<div class="tab-pane" id="adduser-pane"> 
		<div id="" >
				<div class="">
					
					<form id="add-form" class="form-horizontal well">
						<div class="form-group ">
						<input type="hidden" name="id" class="form-control required" value="${user.id }"/>
							<label for="lastName" class="col-lg-2 control-label">角色</label>
							<div class="col-lg-8">							
							<select name="rolesId" id="roles_select" class="form-control">							
							</select>
							</div>
						</div>
						<div class="form-group">
							<label for="loginName" class="col-lg-2 control-label">登录账号</label>
							<div class="col-lg-8">
								<input type="text" id="loginName" name="loginName" class="form-control required" placeholder="手机号码"/>
							</div>
						</div>
						<div class="form-group">
							<label for="name" class="col-lg-2 control-label">昵称</label>
							<div class="col-lg-8">
								<input type="text" id="name" name="name" class="form-control required"/>
							</div>
						</div>
						<div class="form-group">
							<label for="plainPassword" class="col-lg-2 control-label">初始密码</label>
							<div class="col-lg-8">
								<input type="password" id="plainPassword" name="plainPassword" class="form-control required"/>
							</div>
						</div>
						<div class="form-group">
							<label for="lastName" class="col-lg-2 control-label">状态</label>
							<div class="col-lg-2">
									<div class="radio">
										<label class="radio"><input name="status" type="radio"
											value="open" checked="checked"> 激活</label>
									</div>
									<div class="radio">

										<label class="radio"><input name="status" type="radio"
											value="locked"> 锁定</label>
									</div>
								</div>
						</div>
	
						<input type="hidden" value="0" id="fund" name="fund"/>
						<div class="form-group">
							<div class=" col-lg-offset-3">
								<button type="button" class="btn btn-primary add-submit">保存</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
<script type="text/html" id="userList-template">
<table class="table table-striped table-hover table-bordered">
	<thead>
		<tr>
			<th width="3%">id</th>
			<th width="12%">登录名</th>
			<th width="12%">用户名</th>
			<th width="5%">性别</th>
			<th width="10%">角色</th>
			<th width="15%">邮箱</th>
			<th width="10%">注册时间</th>
			<th width="10%">最后登录时间</th>
			<th width="5%">状态</th>			
			<th width="10%">操作</th>
		</tr>
	</thead>
	<tbody >
		<$for(var i = 0;i<result.length;i++){$>
		<tr>
			<td>
				<$=result[i].id$>
			</td>
			<td>
				<$=result[i].loginName$>
			</td>
			<td>
				<$=result[i].name$>
			</td>
			<td class="sex">
				<$
					switch(result[i].gender){  
					case 1: 
				$>男
				<$	
					break;
					case 0:
				$> 女
				<$	
					break;
					default:
				$>
				<$}$>
			</td>
			<td>
				<$=result[i].roles.roleName$>

			</td>
			<td>
				<$=result[i].email$>
			</td>
			<td>
				<$=result[i].registDate$>
			</td>
			<td>
				<$=result[i].lastLoginDate$>
			</td>
			<td>
				<$
					switch(result[i].status){
						case 'open':
				$>激活
				<$		break;
						case 'locked':
				$>锁定
				<$
						break;
						default:
				}$>
			</td>		
			
			<td>
				<div class="btn-group edit">
					<a href="${ctx}/${admin_url}/user/update?uid=<$=result[i].id$>" class="btn btn-defualt"><i class="glyphicon glyphicon-edit"></i></a>
				    <shiro:hasPermission name="user:delete"> 
					<a class="btn btn-defualt"><i class="glyphicon glyphicon-trash" data=<$=result[i].id$>></i></a>
					</shiro:hasPermission>
					<a href="${ctx}/${admin_url}/sendmessage?uid=<$=result[i].id$>" class="btn btn-defualt"><i class="glyphicon glyphicon-envelope" data=<$=result[i].id$>></i> </a>
				
</div>
			</td>
		</tr>
	<$}$>
	</tbody>
</table>
<$ if ( totalPages > 1 ) { $>
	<div class="pagination">
		<$==pagination$>
	</div>
<$ } $>
</script>

<!-- 用户历史消费详情 -->
<script type="text/html" id="fund-table-template">
<$if(result[0]!=null){$>
<div><$
switch(result[0].user.roles){
			case 'sa':
			print("超级管理员");
			break;
			case 'admin':
			print("管理员");
			break;
			case 'institution':
			print("个人服务商");
			break;
			case 'user':
			print("普通");
			break;	
}$>用户 <strong> <$=result[0].userName$></strong> 的收支情况</div>
<div>账户余额：<$=result[0].user.fund$></div>
<$
	var zc=0;
	var sr=0;
for(var i = 0;i<result.length;i++){
	if ( result[i].actionType == 1 ||result[i].actionType == 2 || result[i].actionType == 4) { 
		sr+=result[i].amount;
	}else if ( result[i].actionType == 0 || result[i].actionType == 6){
		zc+=result[i].amount;
	}
}$>
<div>本页收入：<span id="sr"><$=sr$></span></div>
<div>本页支出：<span id="zc"><$=zc$></span></div>
<table class="table table-striped">
	<thead>
		<tr>
			<th>订单号</th>
			<th >时间</th>
			<th >详情</th>
			<th >收支</th>
			<th >金额（元）</th>
		</tr>
	</thead>
	<tbody id="fund-detail-tbody">
		<$for(var i = 0;i<result.length;i++){$>
			<$
				var meg = '';
				if(result[i].payType== '0'){
					msg ="支付宝账户："+  result[i].account;
				}else{
					msg = "银行账户："+ result[i].bank + result[i].account;
				}
			$>
			<tr>
					<td><$=result[i].tradeNo$></td>
					<td ><$=result[i].createdDate$></td>
			<$switch (result[i].actionType){
				case 0:$>	
					<td>支持<b><$="<<"$><$=result[i].project.name$><$=">>"$></b></td>
					<td style="color:red;">支出</td>
					<$break;
				case 1:$>
					<td>支付宝充值</td>
					<td class="brown" style="color:green;">收入</td>
					<$break;
				case 2:$>
					<td>使用优惠券</td>
					<td class="brown" style="color:green;">收入</td>
					<$break;
				case 3:$>	
					<td>充值未生效订单</td>
					<td style="color:gray;">收入</td>
					<$break;
				case 4:$>	
					<td><b><$="<<"$><$=result[i].project.name$><$=">>"$></b>中的服务<b><$="<"$><$=result[i].product.name$><$=">"$></b></td>
					<td style="color:green;">收入</td>
					<$break;
				case 5:$>
					<td>提现申请中 <$=msg$></td>	
					<td style="color:gray;">支出</td>
					<$break;
				case 6:$>	
					<td>提现成功 <$=msg$></td>
					<td style="color:red;">支出</td>
					<$break;
				case 7:$>	
					<td>提现失败 <$=msg$></td>
					<td style="color:gray;">支出</td>
					<$break;
			}$>
					<td class="fundInfor"><$=result[i].amount$></td>			
			</tr>
		<$}$>
	</tbody>
</table>
<$ if ( totalPages > 1 ) { $>
	<div class="pagination">
		<$==pagination$>
	</div>
<$}}else{print("该用户还没有收支情况");}$>
<div class="hf btn btn-link">返回</div>
</script>
<c:if test="${env == 'production' }">
	<script type="text/javascript">
		seajs.use("${ctx}/assets/js-dist/admin/user-list-page");
	</script>
</c:if>
<c:if test="${env != 'production' }">
	<script type="text/javascript">
		seajs.use("${ctx}/assets/js/admin/user-list-page");
	</script>
</c:if>